package shuashuami.hb.com.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

import java.util.List;

import shuashuami.hb.com.entity.agent.ClickerBean;
import shuashuami.hb.com.hbclient.R;
import shuashuami.hb.com.hdlibrary.glid.GlidUtil;

/**
 * <b>类   名：</b>${TYPE_NAME} <br/>
 * <b>类描述：</b> <br/>
 * <b>创建人：</b>zhangqi<br/>
 * <b>创建时间：</b>2017/6/23<br/>
 * <b>修改人：</b>zhangqi<br/>
 * <b>修改时间：</b>2017/6/23<br/>
 * <b>修改备注：</b><br/>
 *
 * @version 1.0.0<br/>
 */
public class AClickManagerAdapter extends BaseAdapter {

    private List<ClickerBean> mResource;
    private Context mContext;
    private LayoutInflater mInflater;
    private GlidUtil glidUtil;


    public AClickManagerAdapter(Context context, List<ClickerBean> lists) {
        this.mContext = context;
        this.mResource = lists;
        mInflater = LayoutInflater.from(context);
        glidUtil = new GlidUtil(context);
    }

    @Override
    public int getCount() {
        return mResource.size();
    }

    @Override
    public Object getItem(int position) {
        return mResource.get(position);
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        ViewHolder holder = null;
        if (convertView == null) {
            holder = new ViewHolder();
            convertView = mInflater.inflate(R.layout.item_click_manager, null);
            holder.imghead = (ImageView) convertView.findViewById(R.id.item_click_imghead);
            holder.txtname = (TextView) convertView.findViewById(R.id.item_click_txtname);
            holder.txtlevel = (TextView) convertView.findViewById(R.id.item_click_txtlevel);
            holder.txtrefer = (TextView) convertView.findViewById(R.id.item_click_txtrefer);
            holder.txtmsg = (TextView) convertView.findViewById(R.id.item_click_txtmsg);
            convertView.setTag(holder);
        } else {
            holder = (ViewHolder) convertView.getTag();
        }
        ClickerBean info = mResource.get(position);
        glidUtil.uploadCircle(info.getAvatar(), holder.imghead, R.mipmap.ic_launcher);
        holder.txtname.setText(info.getUsername());
        if (info.getParent_id().equals("0")) {
            holder.txtlevel.setText("一级");
            holder.txtlevel.setBackgroundResource(R.drawable.shape_corner_red);
        } else {
            holder.txtlevel.setText("二级");
            holder.txtlevel.setBackgroundResource(R.drawable.shape_corner_orange);
        }
        if (!info.getParent_id().equals("0")) {
            holder.txtrefer.setText("(推荐人ID：" + info.getParent_id() + ")");
        }else{
            holder.txtrefer.setText("");
        }
        holder.txtmsg.setText("ID：" + info.getId() + " " + info.getMobile());

        return convertView;
    }


    class ViewHolder {
        ImageView imghead;
        TextView txtname;
        TextView txtlevel;
        TextView txtrefer;
        TextView txtmsg;
    }
}
